<?php
include_once("../includes/page_utf_class.php");
include_once("../config/module_offer_config.php");
//==========================================
if(!empty($_POST["action"])&&$_POST["action"]==lang_show('delete'))
{
	if(isset($_POST["de"]) && is_array($_POST["de"]))
	{
		foreach($_POST['de'] as $v)
		{
			$db->query("select catid,pic from ".INFO." where id='$v'");
			$re=$db->fetchRow();
			update_cat_nums($re['catid'],'del','offer');
			if($re['pic']!=''){
				$pic = explode(',',$re['pic']);
				foreach($pic as $i){
					@unlink($config['webroot'].'/uploadfile/product/'."$i");
					@unlink($config['webroot'].'/uploadfile/product/'.substr($i,0,strrpos($i,'/')+1).'big_'.substr($i,strrpos($i,'/')+1));
				}
			}
		}
		$id=implode(",",$_POST["de"]);
		$db->query("delete from ".INFO." where id in ($id)");
		$db->query("delete from  ".OFFERDETAIL." where offerid in ($id)");
	}
}
//======================================================
if(lang_show('okeyalli')==$_POST["action"])
{
	$db->query("update ".INFO." set statu=1 where statu=0");
}
elseif('audit'==$_GET["submit"]||''!=$_POST['audit'] )
{
	if(isset($_GET['submit'])&&isset($_GET['id'])&&isset($_GET['audit']))
	{
		$sql="update ".INFO." set statu='$_GET[audit]' where id='$_GET[id]'";
		$db->query($sql);
		msg(urldecode($_GET['fw']));//exit();
	}
	if(isset($_POST["de"]) && is_array($_POST["de"])){
		$id=implode(",",$_POST["de"]);
		$audit = $_POST['audit']=='rc'?1:$_POST['audit'];
		$sql="update ".INFO." set statu=$audit where id in ($id)";
		if($_POST['audit']=='rc')
			$sql.= " and statu>1";
		$db->query($sql);
	}
}

$sql="select * from ".OCAT." where catid<9999  order by nums asc";
$db->query($sql);
$infoCatList=$db->getRows();
$i = 0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE><?php echo lang_show('admin_system');?></TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../script/prototype.js"></script>
<script type="text/javascript" src="main.js"></script>
<script src="../script/my_lightbox.js" language="javascript"></script>
<script>
var locat = window.location.href;
function setAudit(v)
{
	if(arguments[1])
		window.location.href = locat+"&submit=audit&id="+arguments[1]+'&audit='+v+'&fw='+encodeURIComponent(locat);
	else{
		$('audit').value = v;
		document.frm.submit();
	}
}
function multi_admin()
{
	 var box_l = document.getElementsByName("de[]").length;
	 for(var j = 0 ; j < box_l ; j++)
	 {
	  	if(document.getElementsByName("de[]")[j].checked==true)
		{
			//var statu = "<?php echo urlencode(serialize(array('未发货','已发货','已完成')));?>";
			alertWin('批量审核','',400,280,"admin_audit.php");
			return;
		}
	 }
	 alert('至少选择一条记录');
	 return false;
}
</script>
</HEAD>
<body>


<div class="bigbox">
	<div class="bigboxhead">
		<span class="cbox on"><a href="module.php?m=offer&s=offerlist.php"><?php echo lang_show('business_list');?></a></span>
		<span class="cbox"><a href="module.php?m=offer&s=offer_move.php">产品转移</a></span>
	</div>
	<div class="bigboxbody">
		<form method="get"  action="">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td class="searh_left"><?php echo lang_show('range');?></td>
		<td >
		  <select class="select" name="type">
			<?php
				$infoType=explode('|',$module_offer_config['infoType']);
				foreach ($infoType as $key=>$value)
				{
					if($key==$_GET["type"]) 
						echo "<option value='$key' selected >$value</option>"; 
					else
						echo "<option value='$key'>$value</option>";
				}
			?>
		  </select>
		  </td>
	  	</tr>
        <tr>
       <td><?php echo lang_show('recommend');?></td>
       <td>
       <?php
          $status=array(
              '4'=>lang_show('all'),
              '-1'=>lang_show('notpass'),
			  '0'=>lang_show('wpass'),
              '1'=>lang_show('auditpass'),
              '2'=>lang_show('recom'),
          );
      ?> 
        <select class="select" name="statu">
        <?php
        foreach($status as $key=>$v)
        {
        ?>
          <option value="<?php echo $key;?>" <?php if(isset($_GET['statu'])&&$_GET['statu']==$key)echo "selected";?>>
            <?php echo $v;?>
          </option>
        <?php
         } 
        ?>
        </select>
       </td>
     </tr>
    <tr>
    <td ><?php echo lang_show('key_word');?></td>
    <td >
	  <?php
		  $title=array(
			  '1'=>lang_show('title'),
			  '2'=>lang_show('introduce'),
			  '3'=>lang_show('key_word'),
			  '4'=>lang_show('supplier')
		  );
	  ?>
	<select class="lselect" name="title">
        <?php
		foreach($title as $key=>$v)
		{
		?>
		<option value="<?php echo $key;?>" <?php if(!empty($_GET['title'])&&$_GET['title']==$key)echo "selected";?>> <?php echo $v;?> </option>
		<?php
		 }
		 ?>
        </select> -- 
    <input class="rtext" name="key" type="text" value="<?php if(!empty($_GET['key'])) echo $_GET['key'];?>" size="35">
	</td>
  </tr>
    <tr>
      <td>&nbsp;</td>
      <td>
	    <input class="btn" type="submit" name="Submit" value="<?php echo lang_show('search');?>">
        <input name="m" type="hidden" value="offer">
        <input name="s" type="hidden" value="offerlist.php">
       </td>
    </tr>
</table></form>
	  <form action="" name='frm' method="POST">
	  <table width="100%" border="0" cellpadding="2" cellspacing="0" >
		<tr class="theader"> 
		  <td width="25"><input onClick="do_select()" type="checkbox" name="checkbox" value="checkbox"></td>
		  <td width="316" ><?php echo lang_show('info_title');?></td>
		  <td width="263" ><?php echo lang_show('tcatid');?></td>
		  <td width="98" align="left" ><?php echo lang_show('update_date');?></td>
		  <td width="68" align="left" ><?php echo lang_show('recommend');?></td>
		  <td width="74" align="left" ><?php echo lang_show('rank');?></td>
		  <td width="52" align="left" ><?php echo lang_show('manager');?></td>
		</tr>
		<?php
		$scl=NULL;
		if(!empty($_GET["key"]))
		{
			if($_GET['title']==1)
				$scl=" and a.title like '%$_GET[key]%' ";
			elseif($_GET['title']==2)
				$scl=" and a.con like '%$_GET[key]%' ";
			elseif($_GET['title']==3)
				$scl=" and a.keyword='$_GET[key]' ";
			else
				$scl=" AND b.company like '%$_GET[key]%' ";
		}
	
		if(isset($_GET["statu"])&&$_GET["statu"]<4)
			$scl.=" AND a.statu=".intval($_GET['statu']);
		if(!empty($_GET['type']))
			$scl.=" and a.type='$_GET[type]' ";
		if($_SESSION["province"])
			$scl.=" and b.province='$_SESSION[province]'";
		if($_SESSION["city"])
			$scl.=" and b.city='$_SESSION[city]'";
			
		$sql="select a.id,a.title,a.catid,a.uptime,a.rank,a.id,b.company,b.ifpay,a.statu,a.pic,a.userid
		from ".INFO." as a left join ".USER." as b on a.userid=b.userid  where 1 $scl order by id desc ";
		//=============================
		$page = new Page;
		$page->listRows=20;
		if (!$page->__get('totalRows')){
			$db->query($sql);
			$page->totalRows = $db->num_rows();
		}
		$sql .= "  limit ".$page->firstRow.",20";
		$pages = $page->prompt();
		//=====================
		$db->query($sql);
		$re=$db->getRows();
		
		unset($_GET['s']);
		$getstr=implode('&',convert($_GET));
		//--------------------------------
		foreach($re as $v)
		{
		?> 
      <tr  onMouseOver="mouseOver(this)" onMouseOut="mouseOut(this,'odd')"> 
        <td width="25"><input name="de[]" type="checkbox" id="de" value="<?php echo $v['id']; ?>"></td>
        <td width="316">
		<?php if(!empty($v['pic'])){?><img src="../image/default/image_s.gif"><?php }?>
		<?php echo $v['title']; ?><br>
		 <a target="_blank" href="../shop.php?uid=<?php echo $v['userid'];?>">
		<?php echo lang_show('supplier');?> [<?php echo $v['company']; ?>]
		</a>
		</td>
        <td align="left">
		<?php 
			$db->query("select cat from ".OCAT." where catid='$v[catid]'");
			$re = $db->fetchRow();
		?>
		<span id="show_cat<?php echo $i?>">
			<a onClick="showCat('<?php echo $i?>');return false;" href="#"><?php echo $re['cat']; ?></a>
		
		<select  style="visibility:hidden" name="catid<?php echo $i?>" id="catid<?php echo $i?>" onChange="getHTML(this.value,'tcatid<?php echo $i?>',<?php echo $i?>,'offer')">
			<option value=""><?php echo lang_show('select_category');?></option>
	<?php			foreach($infoCatList as $option){
		?> 
			<option value="<?php echo $option['catid']; ?>"><?php echo $option['cat']; ?></option>
	<?php		}
		?> 
		</select>
		<select style="visibility:hidden" name="tcatid<?php echo $i?>" id="tcatid<?php echo $i?>" onChange="getHTML(this.value,'scatid<?php echo $i?>',<?php echo $i?>,'offer')">
			<option value=""><?php echo lang_show('select_sub');?></option>
		</select>
		<select style="visibility:hidden"  name="scatid<?php echo $i?>" id="scatid<?php echo $i?>">
			<option value=""><?php echo lang_show('select_sub');?></option>
		</select>
		<span id="mod<?php echo $i?>" style="visibility:hidden"><input type="button" value="<?php echo lang_show('edit');?>" onClick="updateCat('offer',<?php echo $v['id']; ?>,<?php echo $i?>);">	  </td>
        <td width="98" align="left"><?php echo $v["uptime"];?></td>
        <td width="68" align="left">
		<a href="javascript:alertWin('<?php echo lang_show('recommend');?>','',400,280,'admin_audit.php?id=<?php echo $v['id']; ?>&statu=<?php echo $v['statu'];?>');">
			<?php  
			echo $status[$v['statu']]; 
			?> </a></td>
        <td width="74" align="left">&nbsp;<?php echo $v['rank']; ?></td>
        <td width="52" align="left"> 
        <a href="module.php?m=offer&s=offermod.php&id=<?php echo $v['id']."&$getstr"; ?>"><?php echo $editimg;?></a>		</td>
      </tr>
    <?php 
		$i++;
    }
	?> 
  </table>
  <table width="100%" height="20" border="0" cellpadding="4" cellspacing="0">
    <tr>
      <td width="45%">
	  <input class="btn" type="submit" name="action" value="<?php echo lang_show('okeyalli');?>" onClick="return confirm('<?php echo lang_show('are_you_sure');?>');">
	  <input class="btn" type="submit" name="action" value="<?php echo lang_show('delete');?>" onClick="return confirm('<?php echo lang_show('are_you_sure');?>');">
	  <input class="btn"  type="submit" name="action" onclick='multi_admin();return false;' type='submit' value='批量审核' />
	  <input type='hidden' value='' name='audit' id='audit' />
	  </td>
      <td width="65%" align="right"><div class="page"><?php echo $pages?></div></td>
    </tr>
  </table> </form>
  </div>
</div>
 
</body>
</html>
